package com.stormrage.edu.dao.student.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.student.StuAcctDao;
import com.stormrage.entity.student.StuAcct;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: StuAcctDaoImpl.java
 * @Package com.stormrage.edu.dao.student.impl
 * @Description: 学员账户 Dao
 * @author www.stormragetech.com
 * @date 2016年4月15日
 * @version V1.0
 */
@Repository
public class StuAcctDaoImpl extends MysBaseDao implements StuAcctDao {

	private static final Logger logger = LoggerFactory.getLogger(StuAcctDaoImpl.class);

	@Override
	public Integer create(StuAcct arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 Create 】- 开始运行 ");

		final String query = "INSERT INTO stu_acct (acct, pass, salt, type, stu_no, nick_name, reg_date, locked) VALUES"
				+ " (:acct, :pass, :salt, :type, :stuNo, :nickName, :regDate, :locked)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 Create 】- 完成运行 ");
		return index;

	}

	@Override
	public void update(StuAcct arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 StuAcctDao 】- 【 Update 】- 开始运行 ");

		final String query = "UPDATE stu_acct SET acct = :acct, pass = :pass, stu_no = :stuNo WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);
		logger.debug(" 【 Dao 】- 【 StuAcctDao 】- 【 Update 】- 完成运行 ");

	}

	@Override
	public StuAcct queryById(Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 StuAcctDao 】- 【 QueryById 】- 开始运行 ");

		final String query = "SELECT * FROM stu_acct WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		StuAcct entity = queryObject(query, StuAcct.class, map);
		logger.debug(" 查询结果为 " + entity);

		logger.debug(" 【 Dao 】- 【 StuAcctDao 】- 【 QueryById 】- 完成运行 ");
		return entity;

	}

}
